/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dod;

import java.util.List;
import java.util.Arrays;
/**
 *
 * @author tdahl01
 */
public class DoD {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        java.io.BufferedReader stdin = new java.io.BufferedReader(new java.io.InputStreamReader(System.in));

        World world = new World();
        Player player = new Player(world.locations.get(0));
        Object temp;

// Add starting objects to player.obj

        String cmd="I am a sentence"; // replaces the old one String cmd = "";
        List <String> commands = Arrays.asList(cmd.split(" ")); //To make sure we don't get warnings about uninstantiated variables
        cmd = ""; // returns us to the original empty string
        System.out.println("this is a test: "+ commands.get(0)); //This is just a test to show it works
        
        while(!cmd.equalsIgnoreCase("quit")){
            System.out.println("You are "+player.location.desc);
            // This code prints out location objects
            if (player.location.objects.size() > 0) {
                System.out.print("You can see ");  
                int n = player.location.objects.size();
                for(int i = 0; i < n ; i++) {
                	System.out.print( player.location.objects.get(i).desc );
                	if (i <n-1)  System.out.print(", ");
                }
                System.out.println(" here.");
            }
            System.out.println("What next?");
            try{
                cmd = stdin.readLine();
                commands = Arrays.asList(cmd.split(" "));
            }catch(java.io.IOException e){
                System.out.println(e);
            }
            if(commands.get(0).equalsIgnoreCase("n")){
                if(player.location.north!=null){
                    player.location = player.location.north;
                }else{
                    System.out.println("There is no exit to the north.");
                }
            }
            if(commands.get(0).equalsIgnoreCase("e")){
                if(player.location.east!=null){
                    player.location = player.location.east;
                }else{
                    System.out.println("There is no exit to the east.");
                }
            }
            if(commands.get(0).equalsIgnoreCase("s")){
                if(player.location.south!=null){
                    player.location = player.location.south;
                }else{
                    System.out.println("There is no exit to the south.");
                }
            }
            if(commands.get(0).equalsIgnoreCase("w")){
                if(player.location.west!=null){
                    player.location = player.location.west;
                }else{
                    System.out.println("There is no exit to the west.");
                }
            }
            if(commands.get(0).equalsIgnoreCase("take")){
            	//Still assumes player can only hold one object
            	//When used the default first object listed is chosen
            	//The forced swap is still implemented
                 if (player.location.objects.size() > 0) {
                    temp = player.obj;
                    if (temp != null) {
                        player.location.setObject(temp);
                        System.out.println("You drop the "+temp.desc);
                    }
                    player.setObject(player.location.objects.get(0));
                    player.location.objects.remove(0);
                    System.out.println("You take the "+player.obj.desc);

                } else{
                    System.out.println("There is no object here.");
                }
                 // Some test code for multiple word sentences
                 if (commands.size() > 1) {
                     System.out.println("You specified the "+ commands.get(1));
                 }
            }
            if(commands.get(0).equalsIgnoreCase("drop")){
            	// Simply adds the player object to the location list, removing it from the player
            	temp = player.obj;
                if (temp != null) {
                	player.obj = null;
                	player.location.setObject(temp);
                	System.out.println("You drop the "+temp.desc);
                } else{
                   System.out.println("You aren't holding anything.");
                   
                   
                   
                }
            }
            if(commands.get(0).equalsIgnoreCase("quit")){
                System.out.println("You quit.");
            }
        }
        System.out.println("Goodbye!");
        
    }
}
